package com.livestocksolutions.ui;

import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.livestocksolutions.R;
import com.livestocksolutions.intent.BaseActivity;

/* -- Version History --
 *  1.0 : 17 September 2012 - Initial version.
 */

/**
 * A base class to create the layout for a Chemical or Medicine Object
 * @author Adam Parr
 * @version 1.0
 * 
 * @.modified 19 October 2012
 */
public class ViewChemicineArrayAdapter extends ViewUsableItemArrayAdapter {
	/**
	 * Size of the allowable array passed
	 */
	public static final int SIZE = 15;
	/**
	 * The number of days that the Object this is used on will be unavailable for in
	 * position within the String[position][{@value #WITHHOLDPERIOD}] array passed in the
	 * Constructor.
	 */
	public static final int WITHHOLDPERIOD = 10;
	/**
	 * The batch number of this item in position within the String[position][{@value #BATCHNO}]
	 * array passed in the Constructor.
	 */
	public static final int BATCHNO = 11;
	/**
	 * The date of manufacture for this item in position within the
	 * String[position][{@value #MANUFACTUREDATE}] array passed in the Constructor.
	 */
	public static final int MANUFACTUREDATE = 12;
	/**
	 * The date of expiration for the item in position within the
	 * String[position][{@value #EXPIRESDATE}] array passed in the Constructor.
	 */
	public static final int EXPIRESDATE = 13;
	/**
	 * The method in which this item should be applied in position within the
	 * String[position][{@value #APPLICATIONMETHOD}] array passed in the Constructor.
	 */
	public static final int APPLICATIONMETHOD = 14;
	
	/**
	 * Constructor
	 * @param context The current context.
	 * @param values The Group data to represent in the ListView.
	 */
	public ViewChemicineArrayAdapter(BaseActivity context, String[] values) {
		super(context, new String[][]{values});
	}
	
	/**
	 * Constructor
	 * @param context The current context.
	 * @param values The Contacts to represent in the ListView.
	 */
	protected ViewChemicineArrayAdapter(BaseActivity context, String[][] values){
		super(context, values);
	}

	@Override
	public View getView(final int position, View convertView, ViewGroup parent) {
		if(textViewResourceId==0){
			setView(R.layout.item_chemicine_view);
		}
		View rowView = super.getView(position, convertView, parent);
		
		TextView witholdPeriod = (TextView)rowView.findViewById(R.id.withhold);
		TextView batchNo = (TextView)rowView.findViewById(R.id.batchNo);
		TextView manufactureDate = (TextView)rowView.findViewById(R.id.manufactureDate);
		TextView expireDate = (TextView)rowView.findViewById(R.id.expiryDate);
		TextView applicationDesc = (TextView)rowView.findViewById(R.id.applicationDesc);
		
		witholdPeriod.setText(context.getResources().getString(R.string.chemicine_withhold_noDays,values[position][WITHHOLDPERIOD]!=null&&!values[position][WITHHOLDPERIOD].equals("")?(Long.parseLong(values[position][WITHHOLDPERIOD])/1000/60.0/60.0/24.0):0));
		batchNo.setText(values[position][BATCHNO]);
		String s = context.format(context.parse(values[position][MANUFACTUREDATE]));
		manufactureDate.setText(!s.equals("")?s:context.getResources().getString(R.string.message_noText,context.getResources().getString(R.string.message_notSet)));
		s = context.format(context.parse(values[position][EXPIRESDATE]));
		expireDate.setText(!s.equals("")?s:context.getResources().getString(R.string.message_noText,context.getResources().getString(R.string.message_notSet)));
		applicationDesc.setText(values[position][APPLICATIONMETHOD]);

		return rowView;
	}
}
